package de.wowrealmstatus.types;

public enum RealmType {
	Normal,
	PvP,
	RP,
	RPPvP,
	Unknown;
	
	public static RealmType getRealmType (Object object) {
		int num = 0;
		if (object instanceof Integer) {
			num = (Integer) object;
		} else if (object instanceof String) {
			try {
				num = Integer.parseInt((String) object);
			} catch (NumberFormatException nfe) {
				return getByString((String)object);
			}
		}
		if (num != 0) {
			return getByInt(num);
		}
		return Unknown;
	}
	
	private static RealmType getByInt(int num) {
		switch (num) {
		case 1:
			return Normal;
		case 2:
			return PvP;
		case 3:
			return RP;
		case 4:
			return RPPvP;
		default:
			return Unknown;
		}
	}
	
	private static RealmType getByString (String s) {
		s = s.trim();
		for (RealmType t: RealmType.values()) {
			if (s.startsWith(t.toString())) {
				return t;
			}
			if (t == RPPvP && s.startsWith("RP-PvP")) {
				return t;
			}
		}
		return Unknown;
	}
}
